/**
 * One specific ordering/nesting of the coding loops.
 *
 * <p>Copyright 2015, Backblaze, Inc. All rights reserved.
 */
package com.backblaze.erasure;

public class ByteOutputInputTableCodingLoop extends CodingLoopBase {

  @Override
  public void codeSomeShards(
      byte[][] matrixRows,
      byte[][] inputs,
      int inputCount,
      byte[][] outputs,
      int outputCount,
      int offset,
      int byteCount) {

    byte[][] table = Galois.MULTIPLICATION_TABLE;
    for (int iByte = offset; iByte < offset + byteCount; iByte++) {
      for (int iOutput = 0; iOutput < outputCount; iOutput++) {
        byte[] matrixRow = matrixRows[iOutput];
        int value = 0;
        for (int iInput = 0; iInput < inputCount; iInput++) {
          value ^= table[matrixRow[iInput] & 0xFF][inputs[iInput][iByte] & 0xFF];
        }
        outputs[iOutput][iByte] = (byte) value;
      }
    }
  }
}
